package com.df.gamesynctest.command;

import com.df.gamesynctest.entity.GameMap;
import com.df.gamesynctest.entity.Player;
import com.df.gamesynctest.net.MsgManager;
import com.df.gamesynctest.net.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Scanner;

@Component
public class EntryCommand implements CommandLineRunner {

    @Autowired
    private  Server server;

    @Override
    public void run(String... args) throws Exception {

        //启动地图线程
        GameMap.getInstance().start();
        MsgManager.getInstance().registerMsg();
        // 启动网络服务器
        server.start();
        Thread inputT = new Thread(()->{
            Scanner scanner = new Scanner(System.in);

            while (true){
                String next = scanner.next();
                try {
                    Integer i = Integer.valueOf(next);

                    Player player = GameMap.getInstance().players.stream().filter(p -> p.id == i).findFirst().get();
                    if(player!=null){
                        System.out.println("玩家坐标信息："+player.pos);
                    }
                }catch (Exception e){}

            }
        });
        inputT.setDaemon(true);
        inputT.start();
    }
}
